package xin.homeant.upms.service.impl;

import xin.homeant.upms.model.UserRole;
import xin.homeant.cache.annotation.Cache;
import xin.homeant.cache.type.CacheOpType;
import xin.homeant.upms.dao.mapper.UserRoleMapper;
import xin.homeant.upms.service.IRoleService;
import xin.homeant.upms.service.IUserRoleService;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author homeant
 * @since 2017-05-01
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {
	
	@Autowired
	private IRoleService roleService;
	
	@Override
	@Cache(key="'UserRoles'",expire=0,hfield="#args",opType=CacheOpType.READ_WRITE)
	public Set<String> getRolesByUsername(String username) {
		Set<Integer> roleIds = baseMapper.getRoleIdsByUsername(username);
		return roleService.getRolesByIds(roleIds);
	}
}
